<?php
/**
 * Created by JetBrains PhpStorm.
 * User: porterzhang
 * Date: 13-3-5 下午4:44
 * To change this template use File | Settings | File Templates.
 */
if (!defined('IN_MOBILE_API')) {
    exit('Access Denied');
}
include_once 'forum.php';
class cloud_api {
    function common() { }

    function output() {
        global $_G;


        session_start();
        if(strtolower($_SESSION['captcha']['code']) != strtolower($_GET['code'])){
            $variable = array(
                'code' => 50000,
                'messagestr' => lang('plugin/cloud', '50000'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        //判断传入的密码
        if (!$_GET['password'] || $_GET['password'] != addslashes($_GET['password'])) {
            self::setMessage(1015);
        }
        //判断是否缺少参数
        if (empty($_GET['username']) || empty($_GET['caid'])) {
            $variable = array(
                'code' => 1001,
                'messagestr' => lang('plugin/cloud', '1001'),
            );
            cloud_core::result(cloud_core::variable($variable));
        }
        $areaId = empty($_GET['areaId']) ? 0 : $_GET['areaId'];
        //得到登录用户信息

        $manager = C::t('#cloud#cloud_app_manage')->fetch_first_by_name($_GET['username'], $_GET['caid']);
        //当查询出用户的信息不存在时
        if (empty($manager)) {
            self::setMessage(1016);
        }
        //当查询的管理员状态不可用
        if ($manager['status'] == 0) {
            self::setMessage(1017);
        }
        //当查询的管理员密码错误时候
        if (md5(md5($_GET['password']) . $manager['salt']) != $manager['password']) {
            self::setMessage(1016);
        }
        //设置用户登录状态
        //1.得到应用
        $app = C::t('#cloud#cloud_app')->fetch($manager['caid']);
        $manager['app'] = $app;
        //将信息写入到cookie中
        plugin_cloud::setLoginStatus($manager, 'manage', $areaId);
        C::t('#cloud#cloud_app_manage')->update($manager['camid'], array('lasttime' => TIMESTAMP, 'lastip' => $_G['clientip']));

        $variable = array(
            'messagestr' => lang('plugin/cloud', '1013'),
        );

        cloud_core::result(cloud_core::variable($variable));

    }


    /**
     * 返回错误信息
     * @param $code
     */
    function setMessage($code) {
        $variable = array(
            'code' => $code,
            'messagestr' => lang('plugin/cloud', '' . $code),
        );
        cloud_core::result(cloud_core::variable($variable));
    }

}

?>

